﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microserve.TeleEye.BusinessServices;
using Microserve.TeleEye.Common;
using System.Text;
using System.Collections.Generic;

namespace Microserve.TeleEye.Web
{
    public partial class Main : System.Web.UI.MasterPage
    {
        public string pageSpecificTitle = string.Empty;

        public string PageSpecificTitle
        {
            set
            {
                pageSpecificTitle = value + " - ";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            MenuController menuController = new MenuController();
            List<Microserve.TeleEye.Common.MenuBar.MenuItem> mainMenu = menuController.GetMainMenu();

            for (int i = 0; i < mainMenu.Count; i++)
            {
                StringBuilder mItem = new StringBuilder();
                mItem.Append(string.Format(@"<div class=""menuitem"" onmouseover=""select(this, 'submenu{0}', true);""" +
                                @" onmouseout=""select(this, 'submenu{1}', false);"">", i, i));
                mItem.Append(string.Format(@"<div class='menutext'>"));
                mItem.Append(@"<a href=""");
                mItem.Append(mainMenu[i].NavigateUrl);
                mItem.Append(@""">");
                mItem.Append(string.Format(mainMenu[i].Title));
                mItem.Append("</a>");

                if (mainMenu[i].SubMenu.Count > 0)
                {
                    mItem.Append(string.Format(@"<div class=""submenu"" id=""submenu{0}"" style=""display:none;"">", i));
                }

                foreach (Microserve.TeleEye.Common.MenuBar.MenuItem subMenu in mainMenu[i].SubMenu)
                {
                    mItem.Append(@"<div class=""submenutext"" onmouseover=""subselect(this,true);""" +
                            @" onmouseout=""subselect(this,false);"" ><a href=""");
                    mItem.Append(subMenu.NavigateUrl);
                    mItem.Append(@""">");
                    mItem.Append(subMenu.Title);
                    mItem.Append(@"</a>");
                    mItem.Append(@"</div>");
                }

                if (mainMenu[i].SubMenu.Count > 0)
                {
                    mItem.Append(@"</div>");
                }

                mItem.Append(@"</div>");
                mItem.Append(@"</div>");

                LiteralControl ctrl = new LiteralControl(mItem.ToString());
                this.menuBar.Controls.Add(ctrl);
                
                Page.Title = pageSpecificTitle + "TeleEye Philippines - Philippines Digital CCTV Provider | DVR | CCTV Network Camera | IP Camera | Security | Remote Monitoring | Surveillance";
            }

            Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
            Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
            Response.Cache.SetValidUntilExpires(true);

        }
    }
}
